home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / ip / ka9q / osrc.arc / ARP.H < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-26  |  3.8 KB  |  115 lines

  1. #ifndef    ARPSIZE
  2.  
  3. #include "global.h"
  4. #include "timer.h"
  5.  
  6. /* Size of ARP hash table */
  7. #define    ARPSIZE    17
  8.  
  9. /* Lifetime of a valid ARP entry */
  10. #define    ARPLIFE        900    /* 15 minutes */
  11. /* Lifetime of a pending ARP entry */
  12. #define    PENDTIME    15    /* 15 seconds */
  13.  
  14. /* ARP definitions (see RFC 826) */
  15.  
  16. /* Address size definitions */
  17. #define    IPALEN    4        /* Length in bytes of an IP address */
  18. #define    MAXHWALEN    255    /* Maximum length of a hardware address */
  19.  
  20. /* ARP opcodes */
  21. #define    ARP_REQUEST    1
  22. #define    ARP_REPLY    2
  23.  
  24. /* Hardware types */
  25. #define    ARP_NETROM    0    /* Fake for NET/ROM (never actually sent) */
  26. #define    ARP_ETHER    1    /* Assigned to 10 megabit Ethernet */
  27. #define    ARP_EETHER    2    /* Assigned to experimental Ethernet */
  28. #define    ARP_AX25    3    /* Assigned to AX.25 Level 2 */
  29. #define    ARP_PRONET    4    /* Assigned to PROnet token ring */
  30. #define    ARP_CHAOS    5    /* Assigned to Chaosnet */
  31. #define    ARP_ARCNET    7
  32. #define    ARP_APPLETALK    8
  33. extern char *Arptypes[];    /* Type fields in ASCII, defined in arpcmd */
  34. #define    NHWTYPES 9
  35.  
  36. /* Table of hardware types known to ARP */
  37. struct arp_type {
  38.     int16 hwalen;        /* Hardware length */
  39.     int16 iptype;        /* Hardware type field for IP */
  40.     int16 arptype;        /* Hardware type field for ARP */
  41.     int16 pendtime;        /* # secs to wait pending response */
  42.     char *bdcst;        /* Hardware broadcast address */
  43.     int (*format)();    /* Function that formats addresses */
  44.     int (*scan)();        /* Reverse of format */
  45. };
  46. extern struct arp_type Arp_type[];
  47. #define    NULLATYPE    (struct arp_type *)0
  48.  
  49. /* Format of an ARP request or reply packet. From p. 3 */
  50. struct arp {
  51.     int16 hardware;            /* Hardware type */
  52.     int16 protocol;            /* Protocol type */
  53.     char hwalen;            /* Hardware address length, bytes */
  54.     char pralen;            /* Length of protocol address */
  55.     int16 opcode;            /* ARP opcode (request/reply) */
  56.     char shwaddr[MAXHWALEN];    /* Sender hardware address field */
  57.     int32 sprotaddr;        /* Sender Protocol address field */
  58.     char thwaddr[MAXHWALEN];    /* Target hardware address field */
  59.     int32 tprotaddr;        /* Target protocol address field */
  60. };
  61.         
  62. /* Format of ARP table */
  63. struct arp_tab {
  64.     struct arp_tab *next;    /* Doubly-linked list pointers */
  65.     struct arp_tab *prev;    
  66.     struct timer timer;    /* Time until aging this entry */
  67.     struct mbuf *pending;    /* Queue of datagrams awaiting resolution */
  68.     int32 ip_addr;        /* IP Address, host order */
  69.     int16 hardware;        /* Hardware type */
  70.     char *hw_addr;        /* Hardware address */
  71.     char state;        /* (In)complete */
  72. #define    ARP_PENDING    0
  73. #define    ARP_VALID    1
  74.     char pub;        /* Respond to requests for this entry? */
  75. };
  76. struct arp_tab *arp_lookup(),*arp_add();
  77. #define    NULLARP    (struct arp_tab *)0
  78. extern struct arp_tab *Arp_tab[];
  79.  
  80. struct arp_stat {
  81.     unsigned recv;        /* Total number of ARP packets received */
  82.     unsigned badtype;    /* Incoming requests for unsupported hardware */
  83.     unsigned badlen;    /* Incoming length field(s) didn't match types */
  84.     unsigned badaddr;    /* Bogus incoming addresses */
  85.     unsigned inreq;        /* Incoming requests for us */
  86.     unsigned replies;    /* Replies sent */
  87.     unsigned outreq;    /* Outoging requests sent */
  88. };
  89.  
  90.  
  91. #if    defined(__STDC__) || defined(__TURBOC__)
  92. int arp_init(unsigned int hwtype,int hwalen,int iptype,int arptype,
  93.     int pendtime,char *bdcst,int (*format)(),int (*scan)());
  94. char *res_arp(struct iface *iface,int16 hardware,int32 target,struct mbuf *bp);
  95. void arp_input(struct iface *iface,struct mbuf *bp);
  96. struct arp_tab *arp_add(int32 ipaddr,int16 hardware,char *hw_addr,
  97.     int16 hw_alen,int pub);
  98. void arp_drop(struct arp_tab *ap);
  99. struct arp_tab *arp_lookup(int16 hardware,int32 ipaddr);
  100. struct mbuf *htonarp(struct arp *arp);
  101. int ntoharp(struct arp *arp,struct mbuf **bpp);
  102. #else
  103. int arp_init();
  104. char *res_arp();
  105. void arp_input();
  106. struct arp_tab *arp_add();
  107. void arp_drop();
  108. struct arp_tab *arp_lookup();
  109. struct mbuf *htonarp();
  110. int ntoharp();
  111. #endif
  112.  
  113. #endif /* ARPSIZE */
  114.  
  115.